﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class frmDoiMK : Form
    {
        public frmDoiMK()
        {
            InitializeComponent();
        }
        public NHANVIENDTO NvDTO;
        private void frmDoiMK_Load(object sender, EventArgs e)
        {
            lblMaNV.Text = "Mã Nhân viên: " + NvDTO.MaNV.ToString() +
                "\nTên Nhân viên: " + NvDTO.TenNV;
            
            txtMKcu.Focus();
        }

        private void bntLamlai_Click(object sender, EventArgs e)
        {
            txtMKcu.Text = "";
            txtMKmoi.Text = "";
            txtNhaplai.Text = "";
            txtMKcu.Focus();
        }

        private void bntThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void bntOK_Click(object sender, EventArgs e)
        {
            if (txtMKcu.Text.Trim() == "")
            {
                txtMKcu.BackColor = Color.Red;
                txtMKcu.Focus();
                return;
            }
            if (txtMKmoi.Text.Trim() == "")
            {
                txtMKmoi.BackColor = Color.Red;
                txtMKmoi.Focus();
                return;
            }
            if (txtNhaplai.Text.Trim() == "")
            {
                txtNhaplai.BackColor = Color.Red;
                txtNhaplai.Focus();
                return;
            }
            if (txtMKcu.Text.Trim() != NvDTO.MatKhau)
            {
                txtMKcu.BackColor = Color.Red;
                txtMKcu.SelectAll();
                txtMKcu.Focus();
                return;
            }
            if (txtMKmoi.Text != txtNhaplai.Text)
            {
                txtMKmoi.BackColor = Color.Red;
                txtNhaplai.BackColor = Color.Red;
                txtNhaplai.Text = "";
                txtNhaplai.Focus();
                return;
            }

            NHANVIENBUS NvBUS = new NHANVIENBUS();
            NvBUS.SuaNVvoiMK(NvDTO);
            MessageBox.Show("Đổi mật khẩu thành công!");
            NvDTO.MatKhau = txtMKmoi.Text.Trim();
            bntLamlai.PerformClick();
        }

        private void txtMKcu_TextChanged(object sender, EventArgs e)
        {
            if (txtMKcu.TextLength > 0)
                txtMKcu.BackColor = Color.White;
        }

        private void txtNhaplai_TextChanged(object sender, EventArgs e)
        {
            if (txtNhaplai.TextLength > 0)
                txtNhaplai.BackColor = Color.White;
        }

        private void txtMKmoi_TextChanged(object sender, EventArgs e)
        {
            if (txtMKmoi.TextLength > 0)
                txtMKmoi.BackColor = Color.White;
        }
    }
}
